<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        .center{
            width: 1200px;
            margin: 0 auto;
        }
        #footer_center p{
            margin: 0;
        }
        #footer_center h3{
            color: white;
        }
        body{
            background-color: rgb(241,242,243);
        }
        .el-header{
            background-color: white;
        }

        .right-card .el-card__body{
            padding: 0;/*去掉card自带的内边距*/
        }
        .title-p{
            height: 40px;
            overflow: hidden;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
       <my-header></my-header>
        <el-main class="center" >
            <el-row gutter="20">
                <el-col span="18">
                    <el-card>
                        <h2 style="color: orange;text-align: center">
                           {{c.title}}
                        </h2>
                        <p style="font-size: 12px;color: #666;text-align: center">
                            作者:{{c.nickName}} | 发布时间:{{c.createTime}} | 阅读次数:{{c.viewCount}}
                        </p>
                        <el-divider></el-divider>
                        <div v-if="c.type!=2">
                            <el-card style="font-size: 12px">
                                <b style="color: #409EFF">摘要:</b>
                                <p v-html="c.brief"></p>
                            </el-card>
                            <p  v-html="c.content">文章内容</p>
                        </div>
                        <div v-else>
                            <video style="width: 100%" :src="c.videoUrl"
                                   controls type="video/mp4">
                            </video>
                        </div>

                    </el-card>
                    <!--评论相关开始-->
                    <el-card>
                        <p>发一条友善的评论</p>
                        <el-divider></el-divider>
                        <el-row gutter="20">
                            <el-col span="20">
                                <el-input type="textarea" v-model="comment.content" placeholder="说点儿啥..."></el-input>
                            </el-col>
                            <el-col span="2">
                                <el-button @click="post()">发布</el-button>
                            </el-col>
                        </el-row>
                        <!--评论列表开始-->
                        <el-row v-for="c in commentArr" style="margin: 5px 0">
                            <el-col span="2">
                                <el-avatar :src="c.userImgUrl"></el-avatar>
                            </el-col>
                            <el-col span="20">
                                <span style="color: orange;font-weight: bold">{{c.nickName}}:</span>
                                <p style="margin:5px 0">{{c.content}}</p>
                                <span style="color: #666;font-size: 12px">{{c.createTime}}</span>
                            </el-col>
                        </el-row>
                        <!--评论列表结束-->
                    </el-card>
                    <!--评论相关结束-->

                </el-col>
                <el-col span="6">
                    <el-card class="right-card" style="height: 240px;text-align: center;">
                        <div style="background-image: url('imgs/avarbg.jpg');
                        height: 90px"></div>
                        <div style="position: relative;top: -45px">
                            <img :src="c.userImgUrl"
                                 style="border-radius: 90px;border: 5px solid white;
                                width: 90px;height: 90px">
                            <p style="font-size: 20px;margin: 0;
                            font-weight: bold">{{c.nickName}}</p>
                            <i class="el-icon-edit">本文作者</i><br>
                            <i class="el-icon-time">{{c.createTime}}</i>
                        </div>

                    </el-card>
                    <!--作者其它文章开始-->
                    <el-card style="margin:10px 0">
                        <h3>作者其它文章</h3>
                        <el-divider></el-divider>
                        <!--文章列表开始-->
                        <el-row gutter="10" v-for="c in othersArr">
                            <el-col span="10">
                                <a :href="'/detail.html?id='+c.id">
                                <img :src="c.imgUrl" width="100%" height="70px">
                                </a>
                            </el-col>
                            <el-col span="14">
                                <a style="color: #333;text-decoration: none"
                                   :href="'/detail.html?id='+c.id">
                                <p class="title-p" style="margin: 0;">{{c.title}}</p>
                                </a>
                                <i class="el-icon-time" style="color: #666">{{c.createTime}}</i>
                            </el-col>
                        </el-row>
                        <!--文章列表结束-->
                    </el-card>

                    <!--作者其它文章结束-->
                    <!--热门文章开始-->
                    <el-card style="margin:10px 0">
                        <h3>热门文章</h3>
                        <el-divider></el-divider>
                        <!--文章列表开始-->
                        <el-row gutter="10" v-for="c in hotArr">
                            <el-col span="10">
                                <a :href="'/detail.html?id='+c.id">
                                    <img :src="c.imgUrl" width="100%" height="70px">
                                </a>
                            </el-col>
                            <el-col span="14">
                                <a style="color: #333;text-decoration: none"
                                   :href="'/detail.html?id='+c.id">
                                    <p class="title_p" style="margin: 0;">{{c.title}}</p>
                                </a>
                                <i class="el-icon-time" style="color: #666">{{c.createTime}}</i>
                            </el-col>
                        </el-row>
                        <!--文章列表结束-->
                    </el-card>

                    <!--热门文章结束-->
                </el-col>
            </el-row>


        </el-main>
        <el-footer style="height: 280px;background-color: #2f3234;padding:50px 0">
            <my-footer></my-footer>

        </el-footer>
    </el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入Axios-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<!--引入自己的js文件-->
<script src="js/my-header.js"></script>
<script src="js/my-footer.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                c:{},
                othersArr:[],
                hotArr:[],
                comment:{content:""},
                commentArr:[]
            }
        },
        methods: {
            post(){
                if (v.comment.content.trim()==""){
                    v.$message.error("请输入评论的内容!");
                    return
                }
                // let user = JSON.parse(localStorage.user);
                if (localStorage.user==null){
                    alert("请先登录!");
                    location.href="/login.html";
                    return;
                }
                //设置被评论的内容id
                v.comment.contentId = v.c.id;
                axios.post("/v1/comments/add-new",v.comment).then(function (response) {
                    if (response.data.code==1){
                        // alert("评论完成!");
                        v.$message.success("评论完成!");
                        // location.reload();
                    }else{
                        alert("登录超时请重新登录!");
                        location.href="/login.html"
                    }
                })
            },
            loadUserOtherContent(){
                //请求当前文章作者其它内容
                axios.get("/v1/contents/"+v.c.userId+"/others").then(function (response) {
                    if (response.data.code==1){
                        v.othersArr = response.data.data;
                    }
                })
            }
        },
        created:function () {
            let id = new URLSearchParams(location.search).get("id");
            //发请求获取详情内容
            axios.get("/v1/contents/"+id+"/detail").then(function (response) {
                if (response.data.code==1){
                    v.c = response.data.data;
                    //请求其它内容
                    v.loadUserOtherContent();
                }
            })
            //发请求获取热门文章
            axios.get("/v1/contents/hot").then(function (response) {
                if (response.data.code==1){
                    v.hotArr = response.data.data;
                }
            })
            //发请求获取评论
            axios.get("/v1/comments/"+id).then(function (response) {
                if (response.data.code==1){
                    v.commentArr = response.data.data;
                }
            })

        }
    })
</script>
</html>